package com.example.demofdfs.example.map;

import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

import io.swagger.annotations.ApiImplicitParam;

public class ArrayMapTest {
	
	private static final Queue<String> queue = new LinkedList<String>();
	private static int count = 0;

	public static void main(String[] args) {
//		test_1();
//		Map<String, String> map = ArrayMap.syncMap(new ArrayMap<>());
		Map<String, String> map = new ArrayMap<>();
		
		new Thread(()-> {
			while(true) {
				sleep(500L);
				String key = queue.peek();
				System.out.println(Thread.currentThread().getName() + " : " + map.remove(key));
				queue.poll();
			}
		}, "remove-t").start();
		new Thread(()-> {
			while(true) {
				sleep(500L);
				int i = ++count;
				queue.offer("" + i);
				map.put("" + i, "test-" + i);
				System.out.println(Thread.currentThread().getName() + " : " + map);
			}
		}, "put-t").start();
		new Thread(()-> {
			while(true) {
				sleep(500L);
				String key = queue.peek();
				System.out.println(Thread.currentThread().getName() + " : " + map.get(key));
			}
		}, "get-t").start();
		
		
	}
	
	public static void sleep(long m) {
		try {
			Thread.sleep(m);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void test_1() {
		Map<String, String> map = new ArrayMap<>();
		System.out.println(map.isEmpty());
		
		map.put("1", "aa");
		map.put("2", "ss");
		map.put("3", "dd");
		map.put("4", "fff");
		
		System.out.println(map);
		
		System.out.println(map.put("4", "fff"));
		
		System.out.println(map);
		
		System.out.println(map.put("5", "fff"));
		
		System.out.println(map);
		System.out.println("=================");
		System.out.println(map.get("1"));
		System.out.println(map.get("2"));
		System.out.println(map.get("aa"));
		
		System.out.println(map.size());
		
		map.clear();
		System.out.println(map);
		System.out.println(map.isEmpty());
	}

	@ApiImplicitParam
	public void test() {
		System.out.println();
	}
}
